home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / LIB51 / GETS.C < prev    next >
Text File  |  1997-01-12  |  1KB  |  41 lines

  1. /*
  2. ** Gets an entire string from stdin (excluding its newline
  3. ** terminator) or size-1 characters, whichever comes
  4. ** first. The input is terminated by a null character.
  5. ** The user buffer must be large enough to hold the data.
  6. ** Entry: str  = Pointer to destination buffer.
  7. ** Returns str on success, else NULL.
  8. */
  9. gets(str) char *str; {
  10.   return (_gets(str, 32767, stdin, 0));
  11.   }
  12.  
  13. _gets(str, size, fd, nl) char *str; unsigned size, fd, nl; {
  14.   int backup; char *next;
  15.   next = str;
  16.   while(--size > 0) {
  17.     switch (*next = getchar()) {
  18.       case  EOF: *next = NULL;
  19.                  if(next == str) return (NULL);
  20.                  return (str);
  21.       case '\n': *(next + nl) = NULL;
  22.                  return (str);
  23.       case  RUB: if(next > str) backup = 1; else backup = 0;
  24.                  goto backout;
  25.       case WIPE: backup = next - str;
  26.         backout: /*if(iscons(fd)) {*/
  27.                    ++size;
  28.                    while(backup--) {
  29.                      fputs("\b \b", stderr);
  30.                      --next; ++size;
  31.                      }
  32.                    continue;
  33.                    /*}*/
  34.         default: ++next;
  35.       }
  36.     }
  37.   *next = NULL;
  38.   return (str);
  39.   }
  40.  
  41.